import json
import unittest
from api.login import *
from parameterized import parameterized

def build_data():
    test_data = []
    json_file = "../data/login.json"
    with open(json_file,encoding="utf-8") as f:
        json_data = json.load(f)
        for item in json_data:
            login_data = item.get("login_data")
            status = item.get("status")
            success = item.get("success")
            code = item.get("code")
            message = item.get("message")
        test_data.append((login_data, status, success, code, message))
    return test_data
    # login_data, status, success, code, message
class TestLogin(unittest.TestCase):
    def setUp(self):
        self.login_data = LoginAPI()
    def tearDown(self):
        pass
    @parameterized.expand(build_data)
    def test01_case001(self,login_data,status,success,code,message):
        response = self.login_data.login(login_data)
        print(response.json())
        self.assertEqual(status, response.status_code)
        self.assertIn(success, response.json().get("success"))
        self.assertIn(code, response.json().get("code"))
        self.assertIn(message, response.json().get("message"))